package org.example.spring_blog.model;

import lombok.Data;
import org.example.spring_blog.enums.ResultStatus;

@Data
public class Result<T> {

    //业务码
    private ResultStatus code;

    //错误信息
    private String errorMessage;

    //接口返回数据
    private Object data;

    public static <T>Result<T> success(T data){
        Result result = new Result();
        result.setCode(ResultStatus.SUCCESS);
        result.setErrorMessage("");
        result.setData(data);

        return result;
    }

    public static <T>Result<T> fail(String errorMessage){
        Result result = new Result();
        result.setCode(ResultStatus.FAIL);
        result.setErrorMessage("errorMessage");


        return result;
    }

    public static <T>Result<T> fail(String errorMessage, T data){
        Result result = new Result();
        result.setCode(ResultStatus.FAIL);
        result.setErrorMessage("errorMessage");
        result.setData(data);

        return result;
    }


    public static <T>Result<T> noLogin(T data){
        Result result = new Result();
        result.setCode(ResultStatus.SUCCESS);
        result.setErrorMessage("");
        result.setData(data);

        return result;
    }




}
